// __PUBLIC__/js/page/admin/user/adduser
require(['../../common'], function() {
  require(['user.adduser'])
})

define('user.adduser', [
  'jquery',
  'jqp/validate'
], function($) {
  'use strict';

  $('#J_form_add').validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
	  email: {
        required: checkEmailOrPhone
      },
      phone: {
    	required: checkEmailOrPhone
      },
      password: {
        required: '请填写密码',
      },
      nickname: {
        required: '请填写昵称',
      },
    }
  })

  $('#J_form_edit').validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
      email: {
        required: checkEmailOrPhone
      },
      phone: {
    	required: checkEmailOrPhone
      },
      nickname: {
        required: '请填写昵称',
      },
    }
  })
  
  function checkEmailOrPhone(field,v) {
	var msg = true
	var email = $("#email").val()
	var phone = $("#phone").val()
	if (email.length > 0 || phone.length > 0) {
		v.removeErrorClass($("#email"));
		v.removeErrorClass($('#phone'));
		msg = true;
	} else {
		msg = "邮箱或手机号码至少需要填充一个";
	}
	return msg;
  }

})
